﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Collections.Specialized;

namespace Azad.BCL
{
    public class DateTimeUtilities
    {
        public static DateTime GetCurrentDateTime()
        {
            return DateTime.UtcNow.AddHours(5);
        }


        public static string GetDateFromQueryString()
        {
            return DateTimeUtilities.GetDateFromQueryString(HttpContext.Current.Request.QueryString);
        }
        public static string GetDateFromQueryString(NameValueCollection collection)
        {
            Int32 y = collection["y"].ToInt32Safe(); // year
            Int32 m = collection["m"].ToInt32Safe(); // month
            String d = collection["d"]; // magazine no

            String today = null; //DatetimeUtility.GetCurrentDateTime();

            if (y > 0 && m > 0 && String.IsNullOrEmpty(d) == false)
            {
                today = String.Format("/{0}/{1}/{2}/", y.ZeroPad(), m.ZeroPad(), d);
            }

            return today;
        }

        public static string GetLogoDateFromQueryString(NameValueCollection collection)
        {
            Int32 y = collection["y"].ToInt32Safe(); // year
            Int32 m = collection["m"].ToInt32Safe(); // month
            String d = collection["d"]; // magazine no

            String today = null; //DatetimeUtility.GetCurrentDateTime();

            if (y > 0 && m > 0 && String.IsNullOrEmpty(d) == false)
            {
                today = String.Format("/{0}/{1}/{2}/", y.ZeroPad(), m.ZeroPad(), d);
            }

            return today;
        }

        public static string FormatDate(object date)
        {
            return FormatDate(date, "MM/dd/yy");
        }

        public static string FormatDate(object date, string format)
        {
            return String.Format("{0:" + format + "}", Convert.ToDateTime(date));
        }
    }
}
